package com.gang.ssm.bos.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gang.ssm.bos.common.Page;
import com.gang.ssm.bos.core.anotation.Permission;
import com.gang.ssm.bos.core.toolbox.ajax.AjaxResult;
import com.gang.ssm.bos.system.bean.Workordermanage;
import com.gang.ssm.bos.system.service.WorkordermanageService;

/**
 * 工作单
 * @author Administrator
 *
 */
@RequestMapping("/workordermanage")
@Controller
public class WorkordermanageController extends BosController {
	
	@Autowired
	private WorkordermanageService workordermanageService;

	@RequestMapping("/list")
	public String list(Page<Workordermanage> page, 
			Map<String, Object> map) {
		
		workordermanageService.pageQuery(page);
		map.put("page", page);
		
		return "system/qupai/quickworkorderList";
	}
	
	@Permission({ADMIN})
	@ResponseBody
	@RequestMapping("/add")
	public AjaxResult add(Workordermanage workordermanage) {
		try {
			//新添加的工作单为未启动
			workordermanageService.save(workordermanage);
			return success("添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fail("添加失败!");
	}
	
	@RequestMapping("/processList")
	public String list(Map<String, Object> map) {
		List<Workordermanage> list = workordermanageService.findNoStart();
		map.put("list", list);
		return "system/workflow/startransfer";
	}
	
	@ResponseBody
	@RequestMapping("/start/{id}")
	public AjaxResult start(@PathVariable("id") Integer id) {
		try {
			workordermanageService.start(id);
			return success("启动成功!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fail("启动失败!");
	}
}
